package com.yuma.rabbitmq.springbootconsumer.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Component
public class MyRabbitMQListener {

    // 1.从网页测试发送 direct,
    // 2.此方式去监听的队列必须提前已经被创建出来了
    @RabbitListener(queues = "queue0")
    public void receive(String body, Message message, Channel channel){
        System.out.println("监听器监听到了queue0发送的消息：" + body);
    }

    // 2绑定，创建队列，绑定交换机，并指定路由键
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value="direct_exchange", type="direct",ignoreDeclarationExceptions = "true"),
            value = @Queue(value = "direct_queue", durable = "true"),
                    // arguments = @Argument(name = "x-message-ttl", value = "10000",type = "java.lang.Integer")),
            key = "dir"
    ))
    public void receive1(String body, Message message, Channel channel){
        System.out.println("监听器监听到了direct_queue发送的消息：" + body);
    }
}
